#pragma once


#include "ddcl.h"

enum ddcl_DSON_TYPE {
    DDCL_DSON_INTEGER = 1,
    DDCL_DSON_BOOLEAN,
    DDCL_DSON_NUMBER,
    DDCL_DSON_STRING,
    DDCL_DSON_ARRAY,
    DDCL_DSON_MAP,
    DDCL_DSON_PTR,
    DDCL_DSON_NULL,
};

#define DDCL_SIZEOF_DSON 12

//typedef struct tag_ddcl_Dson ddcl_Dson;
typedef char ddcl_Dson;
typedef struct tag_ddcl_DsonValue {
    int type;
    dduint32 size;
    union {
        char b;
        ddint64 integer;
        double number;
        char * string;
        ddcl_Dson * dson;
        void * ptr;
    }u;
}ddcl_DsonValue;


DDCLAPI ddcl_Dson *
ddcl_new_dson (size_t cap);

DDCLAPI void
ddcl_free_dson (ddcl_Dson * dson);

DDCLAPI ddcl_Dson *
ddcl_check_expand_dson (
        ddcl_Dson * dson, size_t cap);

DDCLAPI int
ddcl_begin_dson (ddcl_Dson * dson);

DDCLAPI int
ddcl_next_dson (ddcl_Dson * dson, ddcl_DsonValue * v);

DDCLAPI size_t
ddcl_dson_len (ddcl_Dson * dson);

DDCLAPI ddcl_Dson *
ddcl_clear_dson (ddcl_Dson * dson);

DDCLAPI ddcl_Dson *
ddcl_push_dson_integer (ddcl_Dson * dson, ddint64 num);

DDCLAPI ddcl_Dson *
ddcl_push_dson_boolean (ddcl_Dson * dson, int v);

DDCLAPI ddcl_Dson *
ddcl_push_dson_number (ddcl_Dson * dson, double num);

DDCLAPI  ddcl_Dson *
ddcl_push_dson_string (
        ddcl_Dson * dson, const char * str, dduint32 size);

DDCLAPI ddcl_Dson *
ddcl_push_dson_array (
        ddcl_Dson * dson, ddcl_Dson * array);

DDCLAPI ddcl_Dson *
ddcl_push_dson_map (
        ddcl_Dson * dson, ddcl_Dson * map);

DDCLAPI ddcl_Dson *
ddcl_push_dson_ptr (
        ddcl_Dson * dson, void * ptr, dduint32 size);

DDCLAPI ddcl_Dson *
ddcl_push_dson_null (ddcl_Dson * dson);
